package com.jwthhealth_pub.community.view.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.community.view.CommunityActivity;

import java.util.List;

/**
 * Created by liuzhen on 2017/12/18.
 */

public class CommunityDocAdaper extends RecyclerView.Adapter {
    private final CommunityActivity mActivity;
    private final List<Object> mData;

    public CommunityDocAdaper(CommunityActivity communityActivity, List<Object> list) {
        this.mActivity = communityActivity;
        this.mData = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(View.inflate(mActivity, R.layout.item_community_doc, null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder vh = (ViewHolder) holder;

        vh.clickLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mActivity.showDocInfo();
            }
        });

        vh.btnApply.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mActivity.gotoApplyPage();
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    private class ViewHolder extends RecyclerView.ViewHolder {

        RelativeLayout clickLayout;
        TextView btnApply;

        public ViewHolder(View itemView) {
            super(itemView);

            clickLayout = itemView.findViewById(R.id.layout_click);
            btnApply = itemView.findViewById(R.id.btn_community_doc_analysis);
        }
    }
}
